package com.zhongkai.dao.config;

import java.util.List;

import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

import com.zhongkai.dao.BaseDao;
import com.zhongkai.model.config.Action;

@Component
public class ActionDAO extends BaseDao {

	public void save(Action action) throws Exception {
		getHibernateTemplate().save(action);
	}
	
	public void update(Action action) throws Exception {
		getHibernateTemplate().update(action);
	}
	
	public void saveOrUpdate(Action action) throws Exception {
		getHibernateTemplate().saveOrUpdate(action);
	}
	
	public void saveOrUpdateAll(List<Action> actionList) throws Exception {
		getHibernateTemplate().saveOrUpdateAll(actionList);
	}

	public void delete(Action action) throws Exception {
		getHibernateTemplate().delete(action);
	}

	public Action findById(java.lang.Integer id) throws Exception {
		return (Action) getHibernateTemplate().get("com.zhongkai.model.config.Action", id);
	}

	public List<Action> findByExample(Action action) throws Exception {
		return getHibernateTemplate().findByExample(action);
	}

	public List<Action> findByProperty(String propertyName, Object value) throws Exception {
			String queryString = "from Action as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
	}

	public List<Action> findAll() throws Exception {
			String queryString = "from Action";
			return getHibernateTemplate().find(queryString);
	}

	public Action merge(Action action) throws Exception {
		Action result = (Action) getHibernateTemplate().merge(action);
		return result;
	}

	public void attachClean(Action action) throws Exception {
		getHibernateTemplate().lock(action, LockMode.NONE);
	}

	public static ActionDAO getFromApplicationContext(ApplicationContext ctx) {
		return (ActionDAO) ctx.getBean("ActionDAO");
	}
	
	public List<Action> findByHql(String hql) throws Exception {
		return getHibernateTemplate().find(hql);
	}
	
	public List<Action> findByHql(String hql,Object value) throws Exception {
		return getHibernateTemplate().find(hql, value);
	}
	
	public List<Action> findByHql(String hql,Object[] values) throws Exception {
		return getHibernateTemplate().find(hql, values);
	}
	
	public void exec(String hql) throws Exception {
		getHibernateTemplate().bulkUpdate(hql);
	}
}